{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class Person:    \n",
    "    def sing(self):\n",
    "        print(\"人在唱歌\")\n",
    "        \n",
    "class Student(Person):\n",
    "    def dance(self):\n",
    "        print(\"人在跳舞\")\n",
    "        \n",
    "class Teacher(Person):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "人在跳舞\n",
      "人在唱歌\n",
      "人在唱歌\n"
     ]
    }
   ],
   "source": [
    "s1 = Student()\n",
    "s1.dance()\n",
    "s1.sing()\n",
    "\n",
    "t1 = Teacher()\n",
    "t1.sing()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class Person:  \n",
    "    def __init__(self,name,age):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "        \n",
    "    def sing(self):\n",
    "        print(\"人在唱歌\")\n",
    "        \n",
    "class Student(Person):\n",
    "    def __init__(self,name,age,score):\n",
    "        self.score = score\n",
    "        Person.__init__(self, name, age)\n",
    "    \n",
    "    def dance(self):\n",
    "        print(\"人在跳舞\")\n",
    "        \n",
    "    def sing(self, song):\n",
    "        super().sing()\n",
    "        print(\"在唱%s\"%song)\n",
    "        \n",
    "class Teacher(Person):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "s1 = Student(\"张三\", 18, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('张三', 18, 100)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.name, s1.age, s1.score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "人在唱歌\n",
      "在唱黄河大合唱\n"
     ]
    }
   ],
   "source": [
    "s1.sing(\"黄河大合唱\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
